package com.shop.user.test;

import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.HashMap;
import java.util.Map;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SmsController {

    @PostMapping(value = "/smsXxs/{phone}")
    public Map<String,Object> smsXxs(@PathVariable("phone") String phone) throws Exception {
        Map<String,Object> map = new HashMap<String,Object>(16);
        // 验证码（指定长度的随机数）
        String code = CodeUtil.generateVerifyCode(6);
        String templateParam = "{\"code\":\""+code+"\"}";
        SendSmsResponse response = SmsUtil.sendSms(phone, templateParam);
        map.put("verifyCode",code);
        map.put("phone",phone);

        if( response.getCode().equals("OK")) {
            map.put("status","success");
        } else {
            map.put("isOk","false");
        }
        return map;
    }
}
